//
//  HelpViewController.m
//  FreshBee
//
//  Created by 姜 祥云 on 16/10/15.
//  Copyright © 2016年 iOS013. All rights reserved.
//

#import "HelpViewController.h"
#import "QuestionTableViewController.h"

@interface HelpViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate>
@property (nonatomic,strong)UITableView *tableView;

@end

@implementation HelpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTabview];
    self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationController.navigationBar.hidden=NO;
    
}
-(void)setupTabview
{
    self.title=@"客服帮助";
    
    [self.view addSubview:self.tableView];
    
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(10);
        make.left.bottom.right.equalTo(self.view);
            }];
    self.tableView.rowHeight = 50;
    self.view.backgroundColor=[UIColor lightGrayColor];
    UIView *headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 10)];
    
    self.tableView.tableHeaderView=headView;
    self.tableView.tableFooterView=headView;
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuse = @"reuse";
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (cell == nil) {
        
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }

    

        if (indexPath.row == 0){
            cell.textLabel.text=@"客服电话: 400-8484-842";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
        else
        {
            cell.textLabel.text=@"常见问题";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

        }
    

    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"选中了 %ld 组 %ld行",indexPath.section,indexPath.row);
    

        if(indexPath.row==0){
            [self callHelp];
        }
        else
        {
//            aboutUsViewController *aboutV=[[aboutUsViewController alloc]init];

//            aboutV.hidesBottomBarWhenPushed = YES;

            QuestionTableViewController *questinView=[[QuestionTableViewController alloc]init];
            questinView.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:questinView animated:YES];

            
//            [self.navigationController pushViewController:aboutV animated:YES];
//            //            UITableViewController *controller = segue.destinationViewController;
            
            
        }
    
}
-(void)callHelp
{

//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://400-8484-842"]];
    NSMutableString* str=[[NSMutableString alloc]initWithFormat:@"tel:%@",@"186xxxx6979"];
    UIWebView* callWebview = [[UIWebView alloc]init];
    
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    
    [self.view addSubview:callWebview];
    
    //??打电话是不是要真机测?????
//    [callWebview release];
//    
//    [str release];
    
   
    
}
-(UITableView *)tableView{
    
    if (_tableView == nil) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        
        _tableView.dataSource = self;
        _tableView.delegate = self;
        
    }
    return _tableView;
}


@end
